package com.tywj.panda.travel.details

import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import androidx.fragment.app.FragmentManager
import com.autocareai.lib.extension.visible
import com.tywj.panda.customer.common.view.dialog.BottomDialog
import com.tywj.panda.travel.R
import com.tywj.lib.core.common.extension.onClick
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.lib.route.RouteUtil
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.provider.IH5Service
import kotlinx.android.synthetic.main.travel_refund_status_dialog.*


/**
 * 退款状态对话框
 */
class TravelRefundStatusDialog : BottomDialog() {

    companion object {
        const val TAG = "TravelRefundStatusDialog"
    }

    override fun getLayoutID(): Int = R.layout.travel_refund_status_dialog

    private lateinit var listener: (number: Int) -> Unit

    private var onISeeListener: (() -> Unit)? = null

    private var mTitle = ""
    private var mDes = ""

    //失败才显示协议
    private var isFail = false


    override fun getGravity(): Int = Gravity.CENTER

    override fun getWidth(): Int = WindowManager.LayoutParams.WRAP_CONTENT

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

        tvDes.text = mDes
        tvTitle.text = mTitle

        if (isFail) {
            visible(tvAreegment)
        }
    }

    override fun initListener() {
        super.initListener()

        tvAreegment.onClick {

            RouteUtil.getServiceProvider(IH5Service::class.java)
                ?.toH5Activity(
                    indexUrl = CommonApi.H5_URL + "pages/refund/refund",
                    title = "购票服务协议",
                    titleBgColor = ResourcesUtil.getColor(R.color.common_black_1F),
                    isShowCloseView = false
                )?.navigation(this)
        }

        tvConfirm.onClick {
            onISeeListener?.invoke()
            dismiss()
        }
    }

    //必须点击事件才能关闭
    override fun getCancelOutside(): Boolean = false

    /**
     * 显示弹窗
     */
    fun showRefundStatusDialog(
        fragmentManager: FragmentManager,
        titleTips: String,
        des: String,
        isFail: Boolean = false
    ) {
        this.mTitle = titleTips
        this.mDes = des
        this.isFail = isFail
        showDialog(fragmentManager)
    }

    fun setOnISeeListener(listener: () -> Unit) {
        this.onISeeListener = listener
    }
}